﻿Public Class Busqueda_Egreso

    Dim acceso As New acceso_a_datos
    Dim primera_busqueda As Boolean = False
    Dim combo_Doc_Com As New combo
    Dim codigo_Egreso As Integer

    Private Sub Busqueda_Egreso_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.combo_Doc_Com.cadena_conexion = acceso._CadenaConexion
        Me.acceso._tabla = "Documento_Comercial"


        Me.combo_Doc_Com.cargar(Me.cmb_documento_com, Me.acceso.leo_tabla("cod_Doc_Comercial", "nombre"))
        Me.deshabilitar_Campos()
        Me.carga_grilla()
    End Sub

    Private Sub btn_buscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_buscar.Click
        If Me.primera_busqueda = False Then
            Me.btn_buscar.Enabled = True
            Me.Label1.Visible = True
            Me.Label2.Visible = True
            Me.Label3.Visible = True
            Me.Label4.Visible = True
            Me.Label5.Visible = True
            Me.Label1.Enabled = False
            Me.Label2.Enabled = False
            Me.Label3.Enabled = False
            Me.Label4.Enabled = False
            Me.Label5.Enabled = False
            Me.mask_fecha.Enabled = True
            Me.txt_desc.Enabled = True
            Me.txt_prov.Enabled = True
            Me.cmb_documento_com.Enabled = True
            Me.txt_docu_come.Enabled = True
            Me.lbl_nueva.Visible = False
            Me.lbl_busq.Visible = True
            Me.mask_fecha.Focus()
            Me.primera_busqueda = True
            Me.carga_grilla()
            Me.limpiar_campos()
        Else
            If Me.mask_fecha.Text = "  /  /" And Me.txt_desc.Text = "" And Me.txt_prov.Text = "" _
                And Me.cmb_documento_com.SelectedIndex = -1 And Me.txt_docu_come.Text = "" Then

                MsgBox("Debe ingresar un dato para realizar la busqueda", vbExclamation, "Atencion")
                Me.mask_fecha.Focus()
                Exit Sub
            End If
            Try
                If Not mask_fecha.Text = Format(CDate(mask_fecha.Text), "dd/mm/yyyy") Then
                    MessageBox.Show("La Fecha ingresada es invalida", "IMPORTANTE", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
                    Exit Sub
                End If
            Catch ex As Exception
                MessageBox.Show("La Fecha ingresada es invalida", "IMPORTANTE", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
                Exit Sub
            End Try
            'POR FECHA
            If Me.mask_fecha.Text <> "  /  /" And Me.txt_desc.Text = "" And Me.txt_prov.Text = "" _
                And Me.cmb_documento_com.SelectedIndex = -1 And Me.txt_docu_come.Text = "" Then

                Me.Label1.Visible = False
                Me.Label2.Visible = False
                Me.Label3.Visible = False
                Me.Label4.Visible = False
                Me.Label5.Visible = False
                Me.lbl_nueva.Visible = True
                Me.lbl_busq.Visible = False
                Me.buscar_por_fecha()
                Me.limpiar_campos()
                Me.deshabilitar_Campos()
                Me.primera_busqueda = False
                Exit Sub
            End If
            'POR DESCRICPION
            If Me.mask_fecha.Text = "  /  /" And Me.txt_desc.Text <> "" And Me.txt_prov.Text = "" _
                And Me.cmb_documento_com.SelectedIndex = -1 And Me.txt_docu_come.Text = "" Then

                Me.Label1.Visible = False
                Me.Label2.Visible = False
                Me.Label3.Visible = False
                Me.Label4.Visible = False
                Me.Label5.Visible = False
                Me.lbl_nueva.Visible = True
                Me.lbl_busq.Visible = False
                Me.buscar_por_descripcion()
                Me.limpiar_campos()
                Me.deshabilitar_Campos()
                Me.primera_busqueda = False
                Exit Sub
            End If
            'POR PROVEEDOR
            If Me.mask_fecha.Text = "  /  /" And Me.txt_desc.Text = "" And Me.txt_prov.Text <> "" _
                And Me.cmb_documento_com.SelectedIndex = -1 And Me.txt_docu_come.Text = "" Then

                Me.Label1.Visible = False
                Me.Label2.Visible = False
                Me.Label3.Visible = False
                Me.Label4.Visible = False
                Me.Label5.Visible = False
                Me.lbl_nueva.Visible = True
                Me.lbl_busq.Visible = False
                Me.buscar_por_proveedor()
                Me.limpiar_campos()
                Me.deshabilitar_Campos()
                Me.primera_busqueda = False
                Exit Sub
            End If
            'POR DOCUMENTO
            If Me.mask_fecha.Text = "  /  /" And Me.txt_desc.Text = "" And Me.txt_prov.Text = "" _
                And Me.cmb_documento_com.SelectedIndex <> -1 And Me.txt_docu_come.Text = "" Then

                Me.Label1.Visible = False
                Me.Label2.Visible = False
                Me.Label3.Visible = False
                Me.Label4.Visible = False
                Me.Label5.Visible = False
                Me.lbl_nueva.Visible = True
                Me.lbl_busq.Visible = False
                Me.buscar_por_doc_com()
                Me.limpiar_campos()
                Me.deshabilitar_Campos()
                Me.primera_busqueda = False
                Exit Sub
            End If
            'POR NUMERO DE DOCUMENTO
            If Me.mask_fecha.Text = "  /  /" And Me.txt_desc.Text = "" And Me.txt_prov.Text = "" _
                And Me.cmb_documento_com.SelectedIndex = -1 And Me.txt_docu_come.Text <> "" Then

                Me.Label1.Visible = False
                Me.Label2.Visible = False
                Me.Label3.Visible = False
                Me.Label4.Visible = False
                Me.Label5.Visible = False
                Me.lbl_nueva.Visible = True
                Me.lbl_busq.Visible = False
                Me.buscar_por_num_doc_com()
                Me.limpiar_campos()
                Me.deshabilitar_Campos()
                Me.primera_busqueda = False
                Exit Sub
            End If
            'POR FECHA Y DESC
            If Me.mask_fecha.Text <> "  /  /" And Me.txt_desc.Text <> "" And Me.txt_prov.Text = "" _
                And Me.cmb_documento_com.SelectedIndex = -1 And Me.txt_docu_come.Text <> "" Then

                Me.Label1.Visible = False
                Me.Label2.Visible = False
                Me.Label3.Visible = False
                Me.Label4.Visible = False
                Me.Label5.Visible = False
                Me.lbl_nueva.Visible = True
                Me.lbl_busq.Visible = False
                Me.buscar_por_fecha_desc()
                Me.limpiar_campos()
                Me.deshabilitar_Campos()
                Me.primera_busqueda = False
                Exit Sub
            End If
            'POR FECHA Y DOCUMENTO
            If Me.mask_fecha.Text <> "  /  /" And Me.txt_desc.Text = "" And Me.txt_prov.Text = "" _
                And Me.cmb_documento_com.SelectedIndex <> -1 And Me.txt_docu_come.Text = "" Then

                Me.Label1.Visible = False
                Me.Label2.Visible = False
                Me.Label3.Visible = False
                Me.Label4.Visible = False
                Me.Label5.Visible = False
                Me.lbl_nueva.Visible = True
                Me.lbl_busq.Visible = False
                Me.buscar_por_fecha_doc()
                Me.limpiar_campos()
                Me.deshabilitar_Campos()
                Me.primera_busqueda = False
                Exit Sub
            End If
            'POR DESC Y NUMERO DOCU
            If Me.mask_fecha.Text = "  /  /" And Me.txt_desc.Text <> "" And Me.txt_prov.Text = "" _
                And Me.cmb_documento_com.SelectedIndex <> -1 And Me.txt_docu_come.Text <> "" Then

                Me.Label1.Visible = False
                Me.Label2.Visible = False
                Me.Label3.Visible = False
                Me.Label4.Visible = False
                Me.Label5.Visible = False
                Me.lbl_nueva.Visible = True
                Me.lbl_busq.Visible = False
                Me.buscar_por_desc_doc()
                Me.limpiar_campos()
                Me.deshabilitar_Campos()
                Me.primera_busqueda = False
                Exit Sub
            End If

            Me.Label1.Visible = False
            Me.Label2.Visible = False
            Me.Label3.Visible = False
            Me.Label4.Visible = False
            Me.Label5.Visible = False
            Me.lbl_nueva.Visible = True
            Me.lbl_busq.Visible = False
            Me.buscar_otro()
            Me.limpiar_campos()
            Me.deshabilitar_Campos()
            Me.primera_busqueda = False
        End If
    End Sub

    'POR FECHA
    Private Sub buscar_por_fecha()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim c As Integer

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE E.fecha='" & Me.mask_fecha.Text & "'"

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso con la fecha especificada", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'POR DESCRIPCION
    Private Sub buscar_por_descripcion()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim c As Integer

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE DE.descripcion LIKE '%" & Me.txt_desc.Text & "%'"

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso con la descripcion especificada", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'POR PROVEEDOR
    Private Sub buscar_por_proveedor()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim c As Integer

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE DE.nombre_Proveedor LIKE '%" & Me.txt_prov.Text & "%'"

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso con el proveedor especificado", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'POR NOMBRE DOC COMERCIAL
    Private Sub buscar_por_doc_com()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim c As Integer

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE DE.cod_Documento_Comercial=" & Me.cmb_documento_com.SelectedIndex

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso que coincida con el tipo de documento especificado", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'POR NUMERO DOC COMERCIAL
    Private Sub buscar_por_num_doc_com()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim c As Integer

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE DE.num_Doc_Com=" & Me.txt_docu_come.Text

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso con el número de documento especificado", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'POR FECHA Y DESCRICPION
    Private Sub buscar_por_fecha_desc()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim c As Integer

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE E.fecha='" & Me.mask_fecha.Text & "' "
        consulta += "AND DE.descripcion LIKE '%" & Me.txt_desc.Text & "%'"

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso con esa fecha y descripcion", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'POR FECHA DE DOCUMENTO
    Private Sub buscar_por_fecha_doc()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim c As Integer

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE E.fecha='" & Me.mask_fecha.Text & "' "
        consulta += "AND DE.cod_Documento_Comercial=" & Me.txt_docu_come.Text

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso con la fecha y tipo de doc. com. especificado", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'POR DESCRIPCION Y DOCUMENTO
    Private Sub buscar_por_desc_doc()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim c As Integer

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE DE.descripcion LIKE '%" & Me.txt_desc.Text & "%' "
        consulta += "AND DE.cod_Documento_Comercial=" & Me.cmb_documento_com.SelectedIndex

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso correspondiente a esa descricion y doc. comercial", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'POR OTRO
    Private Sub buscar_otro()
        Dim tabla As New Data.DataTable
        Dim consulta As String = ""
        Dim aux As String = ""
        Dim var As Boolean = False
        Dim c As Integer

        If Me.mask_fecha.Text <> "  /  /" Then
            aux += "E.fecha='" & Me.mask_fecha.Text & "'"
            var = True
        End If

        If Me.txt_desc.Text <> "" Then
            If var = True Then
                aux += " AND DE.descripcion LIKE '%" & Me.txt_desc.Text & "%'"
            Else
                aux += "DE.descripcion LIKE '%" & Me.txt_desc.Text & "%'"
                var = True
            End If
        End If

        If Me.txt_prov.Text <> "" Then
            If var = True Then
                aux += " AND DE.nombre_Proveedor LIKE '%" & Me.txt_prov.Text & "%'"
            Else
                aux += "DE.nombre.Proveedor LIKE '%" & Me.txt_prov.Text & "%'"
                var = True
            End If
        End If

        If Me.cmb_documento_com.SelectedIndex <> -1 Then
            If var = True Then
                aux += " AND DE.cod_Documento_Comercial=" & Me.cmb_documento_com.SelectedIndex
            Else
                aux += "DE.cod_Documento_Comercial=" & Me.cmb_documento_com.SelectedIndex
                var = True
            End If
        End If

        If Me.txt_docu_come.Text <> "" Then
            If var = True Then
                aux += " AND DE.num_Doc_Com=" & Me.txt_docu_come.Text
            Else
                aux += "DE.num_Doc_Com=" & Me.txt_docu_come.Text
                var = True
            End If
        End If

        consulta = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        consulta += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        consulta += "INNER JOIN Documento_Comercial DC ON DE.cod_Documento_Comercial=DC.cod_Doc_Comercial "
        consulta += "WHERE " & aux

        tabla = acceso._consulta(consulta)

        Me.grilla_Egreso.Rows.Clear()

        If tabla.Rows.Count <> 0 Then
            For c = 0 To tabla.Rows.Count - 1
                Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
            Next

            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Exit Sub
        Else
            MsgBox("No se encontro ningun Egreso con los parametros especificados", vbExclamation, "Importante")
            Me.mask_fecha.Text = ""
            Me.mask_fecha.Focus()
            Me.carga_grilla()
        End If
    End Sub

    'CARGA GRILLA
    Private Sub carga_grilla()
        Dim tabla As New Data.DataTable
        Dim txt_sql As String = ""
        Dim c As Integer = 0

        txt_sql = "SELECT E.cod_Egreso as cod, E.fecha, DE.descripcion as des, DE.nombre_Proveedor as nom_Prov, DE.monto, DE.num_Doc_Com as num, DC.nombre "
        txt_sql += "FROM Egreso E INNER JOIN Detalle_Egreso DE ON E.cod_Egreso=DE.cod_Egreso "
        txt_sql += "INNER JOIN Documento_Comercial DC ON DC.cod_Doc_Comercial=DE.cod_Documento_Comercial"

        'obtengo los datos de la consulta
        tabla = Me.acceso._consulta(txt_sql)

        Me.grilla_Egreso.Rows.Clear()

        For c = 0 To tabla.Rows.Count - 1
            Me.grilla_Egreso.Rows.Add(tabla.Rows(c)("cod"), FormatDateTime(tabla.Rows(c)("fecha"), DateFormat.ShortDate), tabla.Rows(c)("des"), tabla.Rows(c)("nom_Prov"), tabla.Rows(c)("nombre"), tabla.Rows(c)("num"), tabla.Rows(c)("monto"))
        Next
    End Sub


    Private Sub deshabilitar_Campos()
        'campos
        Me.mask_fecha.Enabled = False
        Me.txt_prov.Enabled = False
        Me.txt_desc.Enabled = False
        Me.cmb_documento_com.Enabled = False
        Me.txt_docu_come.Enabled = False

        Me.cmb_documento_com.SelectedIndex = -1
        'botones
        Me.btn_buscar.Enabled = True
       
    End Sub

    Private Sub habilitar_Campos()
        'campos
        Me.mask_fecha.Enabled = True
        Me.txt_prov.Enabled = True
        Me.txt_desc.Enabled = True
        Me.cmb_documento_com.Enabled = True
        Me.txt_docu_come.Enabled = True


        'botones
        Me.btn_buscar.Enabled = True
      
    End Sub

    Private Sub limpiar_campos()
        Me.mask_fecha.Text = ""
        Me.txt_prov.Text = ""
        Me.txt_desc.Text = ""
        Me.cmb_documento_com.SelectedIndex = -1
        Me.txt_docu_come.Text = ""

    End Sub

    Private Sub btn_volver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_volver.Click
        Close()

    End Sub

    Private Sub Busqueda_Egreso_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Dispose()
    End Sub
End Class